package com.gz.mylife.im;

import android.os.Parcel;
import android.os.Parcelable;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Property;
import net.tsz.afinal.annotation.sqlite.Table;
import net.tsz.afinal.annotation.sqlite.Transient;

/**
 * 聊天室的消息内容 
 * @author linwenming
 *
 */
@Table(name="tb_imessage")
public class IMessage implements Parcelable{

	// type = 1文字 2图片 3声音   jpush对应的t
	@Transient
	public static final int TYPE_TEXT = 1;
	@Transient
	public static final int TYPE_PHOTO = 2;
	@Transient
	public static final int TYPE_AUDIO = 3;
	@Transient
	public static final int TYPE_SHARE = 4;
	
	// stete = 0正常的消息 1正在上传的消息 2失败的消息
	@Transient
	public static final int STATE_NORMAL = 0;
	@Transient
	public static final int STATE_UPLOADING = 1;
	@Transient
	public static final int STATE_FAILURE = 2;
	
	public IMessage() {
		// TODO Auto-generated constructor stub
	}
	
	@Id
	private int id;
	@Property
	private int lastid;
//	private int uid;
	@Property
	private int pmid;
	@Property
	private int toUid;
	@Property
	private int fromUid; 
	@Property
	private String content;
	@Property
	private String picture;
	@Property
	private String picture_thumb;
	@Property
	private int width;
	@Property
	private int height;
	@Property
	private String audio;
	@Property
	private long dateline;
	@Property
	private int showType;
	@Property
	private boolean isComMsg;
	@Property
	private int myType;//区分分享和正常消息，1分享，0消息,2分享长贴 ,-1 系统消息
	@Property
	private int discuzId;
	@Property
	private int topicId;
	@Property
	private int msgId;
	@Property
	private int gender; //0 女性 ，1 男性
	@Property
	private int isConnect;
	@Property
	private int maxMsgId;//出现消息丢失时本地的最大消息id
	@Property
	private String tieUrl;
	@Property
	private int currentUID;
	
	
	@Transient
	public boolean inShowTime;
	
	/**
	 * 发送消息\上传图片
	 * 0:正常的  1正在上传 2上传失败
	 */
	@Transient
	public int inMsgState;
	
	// 用于请求完成后绑定对象所在当前位置
	@Transient
	public String inUUID;

	
	
	
	public int getCurrentUID() {
		return currentUID;
	}

	public void setCurrentUID(int currentUID) {
		this.currentUID = currentUID;
	}

	public String getTieUrl() {
		return tieUrl;
	}

	public void setTieUrl(String tieUrl) {
		this.tieUrl = tieUrl;
	}

	public int getIsConnect() {
		return isConnect;
	}

	public void setIsConnect(int isConnect) {
		this.isConnect = isConnect;
	}

	public int getMaxMsgId() {
		return maxMsgId;
	}

	public void setMaxMsgId(int maxMsgId) {
		this.maxMsgId = maxMsgId;
	}

	public int getMsgId() {
		return msgId;
	}

	public void setMsgId(int msgId) {
		this.msgId = msgId;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public int getDiscuzId() {
		return discuzId;
	}

	public void setDiscuzId(int discuzId) {
		this.discuzId = discuzId;
	}

	public int getTopicId() {
		return topicId;
	}

	public void setTopicId(int topicId) {
		this.topicId = topicId;
	}

	public int getShowType() {
		return showType;
	}

	public void setShowType(int type) {
		this.showType = type;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public int getLastid() {
		return lastid;
	}

	public void setLastid(int lastid) {
		this.lastid = lastid;
	}

//	public int getUid() {
//		return uid;
//	}
//
//	public void setUid(int uid) {
//		this.uid = uid;
//	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getAudio() {
		return audio;
	}

	public void setAudio(String audio) {
		this.audio = audio;
	}

	public long getDateline() {
		return dateline;
	}

	public void setDateline(long dateline) {
		this.dateline = dateline;
	}

	public boolean isComMsg() {
		return isComMsg;
	}

	public void setComMsg(boolean isComMsg) {
		this.isComMsg = isComMsg;
	}
	
	public int getPmid() {
		return pmid;
	}

	public void setPmid(int pmid) {
		this.pmid = pmid;
	}

	public int getToUid() {
		return toUid;
	}

	public void setToUid(int to) {
		this.toUid = to;
	}

	public int getFromUid() {
		return fromUid;
	}

	public void setFromUid(int from) {
		this.fromUid = from;
	}
	
	public String getPicture_thumb() {
		return picture_thumb;
	}

	public void setPicture_thumb(String picture_thumb) {
		this.picture_thumb = picture_thumb;
	}
	
	

	public int getMyType() {
		return myType;
	}

	public void setMyType(int myType) {
		this.myType = myType;
	}
	

	public IMessage(Parcel source) {
		lastid =source.readInt();
//		uid = source.readInt();
		pmid = source.readInt();
		toUid = source.readInt();
		fromUid = source.readInt();
		content = source.readString();
		picture = source.readString();
		picture_thumb = source.readString();
		width = source.readInt();
		height = source.readInt();
		audio = source.readString();
		dateline =source.readLong();
		showType = source.readInt();
		isComMsg =source.readInt() == 1? true:false;
		myType = source.readInt();
		discuzId = source.readInt();
		topicId = source.readInt();
		msgId = source.readInt();
		gender = source.readInt();
		isConnect = source.readInt();
		maxMsgId = source.readInt();
	}

	@Override
	public int describeContents() {
		return 0;
	}
	
	

	@Override
	public String toString() {
		return "IMessage [id=" + id + ", lastid=" + lastid + ", pmid=" + pmid
				+ ", toUid=" + toUid + ", fromUid=" + fromUid + ", content="
				+ content + ", picture=" + picture + ", picture_thumb="
				+ picture_thumb + ", width=" + width + ", height=" + height
				+ ", audio=" + audio + ", dateline=" + dateline + ", showType="
				+ showType + ", isComMsg=" + isComMsg + ", myType=" + myType
				+ ", discuzId=" + discuzId + ", topicId=" + topicId
				+ ", msgId=" + msgId + ", gender=" + gender + ", isConnect="
				+ isConnect + ", maxMsgId=" + maxMsgId + ", inShowTime="
				+ inShowTime + ", inMsgState=" + inMsgState + ", inUUID="
				+ inUUID + "]";
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		
		dest.writeInt(lastid);
//		dest.writeInt(uid);
		dest.writeInt(pmid);
		dest.writeInt(toUid);
		dest.writeInt(fromUid);
		dest.writeString(content);
		dest.writeString(picture);
		dest.writeString(picture_thumb);
		dest.writeInt(width);
		dest.writeInt(height);
		dest.writeString(audio);
		dest.writeLong(dateline);
		dest.writeInt(showType);
		dest.writeInt((isComMsg?1:0));
		dest.writeInt(myType);
		dest.writeInt(discuzId);
		dest.writeInt(topicId);
		dest.writeInt(msgId);
		dest.writeInt(gender);
		dest.writeInt(isConnect);
		dest.writeInt(maxMsgId);
	}
	
	public static final Parcelable.Creator<IMessage> CREATOR = new Creator<IMessage>() {
		
		@Override
		public IMessage[] newArray(int size) {
			return new IMessage[size];
		}
		
		@Override
		public IMessage createFromParcel(Parcel source) {
			return new IMessage(source);
		}
	};
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof IMessage){
			IMessage msg =((IMessage)o);
			if(pmid == msg.pmid && lastid == msg.getLastid()){
				return true;
			}
		}
		return false;
	}
}
